package com.concurrency.example.adapter;

import com.concurrency.example.adapter.classDemo.SdAdapterTf;
import com.concurrency.example.adapter.objectDemo.SdAdapterTfObject;
import org.junit.Test;

/**
 * 适配器模式测试类
 */
public class AdapterTest {
    /**
     * 类适配器模式测试类
     * 以一个类继承适配者，并实现适配目标的接口，达到适配的目的
     */
    @Test
    public void fun1(){
        Computer computer = new Computer();

        SdCard sdCard = new SdCardImpl();
        System.out.println(computer.read(sdCard));

        System.out.println("================");

        sdCard = new SdAdapterTf();
        System.out.println(computer.read(sdCard));
    }

    /**
     * 对象适配器模式测试类
     * 以一个类组合适配者（成员变量），并继承适配目标，达到适配的目的
     * 此种用于适配的对象没有实现接口的情况
     */
    @Test
    public void fun2(){
        Computer computer = new Computer();

        SdCard sdCard = new SdCardImpl();
        System.out.println(computer.read(sdCard));

        System.out.println("================");

        sdCard = new SdAdapterTfObject(new TfCardImpl());
        System.out.println(computer.read(sdCard));
    }
}
